<template>
	<div id="githubLogin">
		<h1 v-show='!isLogin'>正在登录中，请耐心等待~~</h1>
		<div v-show='isLogin'>
			<h2>登录成功,即将跳转到首页~~~</h2>
		</div>
	</div>
</template>
<script>
	import {githubLogin} from '@/api/user'
	export default{
		name:'githubLogin',
		data(){
			return{
				username:'',
				avatorPath:'',
				isLogin:false
			}
		},
		methods:{
			GetQueryString(name){
		     	let reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
		     	let r = window.location.search.substr(1).match(reg);
		     	if(r!=null)return  unescape(r[2]); return null;
			},
			async githubLogin(){
				let {userInfo:[user],token}=await githubLogin(this.GetQueryString('code'));
				this.isLogin=true;
				sessionStorage.setItem('name',user.name);
				sessionStorage.setItem('avator',user.avator);
				sessionStorage.setItem('id',user.id);
				sessionStorage.setItem('role',user.role);
				sessionStorage.setItem('email','');
				sessionStorage.setItem('phone',user.phone);
				sessionStorage.setItem('create_time',user.create_time);
				sessionStorage.setItem('token',token);
				sessionStorage.setItem('githubLogin',1);
				setTimeout(()=>{
					location='/';
				},1600)
			}
		},
		created(){
			if(!this.GetQueryString('code')){
				location='/';
				return;
			}
			this.githubLogin();
		}
	}
</script>
<style>
	
</style>